﻿<?xml version="1.0" encoding="UTF-8" ?>
<?arg urn:xmd-environment=Adoor.Metadata.XmdEnvironment, Adoor.Metadata ?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:typing="urn:xmd-typing"
	xmlns:mapping="urn:xmd-mapping"
	xmlns:env="urn:xmd-environment">
	
<xsl:output method="text"/>
	
<xsl:template match="/"><xsl:variable name="SetTotal" select="env:SetProgressTotal(count(/*/*[typing:entity]) + count(/*/*[typing:interface]))" xmlns:env="urn:xmd-environment" /><xsl:apply-templates/></xsl:template>

<CSharpInput/>


<!--<xsl:template match="@type[.='System.String']">""</xsl:template>
<xsl:template match="@type[.='System.Boolean']">false</xsl:template>
<xsl:template match="@type[.='System.Int32']">0</xsl:template>
<xsl:template match="@type[.='System.DateTime']">DateTime.Parse("1800-01-01T00:00:00")</xsl:template>
<xsl:template match="@type[.='System.Decimal']">0</xsl:template>
<xsl:template match="@type[.='System.Double']">0</xsl:template>
<xsl:template match="@type[.='System.Single']">0</xsl:template>
<xsl:template match="@type[.='System.Byte[]']">new Byte[0]</xsl:template>
<xsl:template match="@type">
	<xsl:message terminate="yes">datatype <xsl:value-of select="."/> not defined</xsl:message>	
</xsl:template>-->

<xsl:template match="*[typing:entity]">---- File: <xsl:value-of select="env:FilePath(typing:entity/@type)"/>\<xsl:value-of select="env:TypeName(typing:entity/@type)"/>.cs
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;

#region user code using
#endregion user code using

namespace <xsl:value-of select="env:NamespaceName(typing:entity/@type)"/>
{
	#region user code namespace
	#endregion user code namespace
	
	<xsl:variable name="log" select="env:Log(concat('Processing type ', env:TypeName(typing:entity/@type)),'0')" xmlns:env="urn:xmd-environment"/>
	<xsl:variable name="progress" select="env:UpdateProgress()" xmlns:env="urn:xmd-environment"/>

	<xsl:call-template name="summary"/>
	public abstract class <xsl:value-of select="env:TypeName(typing:entity/@type)"/><xsl:if test="typing:entity/@parent"> : <xsl:value-of select="env:FullTypeName(typing:entity/@parent)"/></xsl:if>
	<xsl:for-each select="typing:interfaces/typing:interface">
		<xsl:choose><xsl:when test="typing:entity/@parent"> , </xsl:when>
		<xsl:otherwise> : </xsl:otherwise></xsl:choose> <xsl:value-of select="env:FullTypeName(@type)"/>
	</xsl:for-each>
	#region user code implements
	#endregion user code implements
	{
	<xsl:apply-templates select="*[*[not(@inherited='true')]]" mode="public"/>
	
		<xsl:choose><xsl:when test="typing:entity/@parent">
		
		public override System.String ModifiePar
		{
			get
			{
				System.String  value = base.ModifiePar;
				#region user code get public System.String ModifiePar
				#endregion user code get public System.String ModifiePar
				return value; 
			}
		}
		
		public override System.DateTime ModifieLe
		{
			get
			{
				System.DateTime  value = base.ModifieLe;
				#region user code get public System.String ModifieLe
				#endregion user code get public System.String ModifieLe
				return value; 
			}
		}
		
		public override System.String TableName
		{
			get
			{
				System.String  value = base.TableName;
				#region user code get public System.String TableName
				#endregion user code get public System.String TableName
				return value; 
			}
		}
		
		/// &lt;summary&gt;
		/// Called when user is creating a new entity.
		/// &lt;/summary&gt;
		protected override void OnCreate(object[] args)
		{
			base.OnCreate(args);
<xsl:call-template name="defaultValues" />
			#region user code OnCreate
			#endregion user code OnCreate
		}
				
		/// &lt;summary&gt;
		/// Called when user is retreiving an entity from storage
		/// &lt;/summary&gt;
		protected override void OnMaterialize()
		{
			base.OnMaterialize();
			#region user code OnMaterialize
			#endregion user code OnMaterialize
		}
		</xsl:when>
		<xsl:otherwise>
		
		/// &lt;summary&gt;
		/// Called when user is creating a new entity.
		/// &lt;/summary&gt;
		protected virtual void OnCreate(object[] args)
		{
<xsl:call-template name="defaultValues" />
			#region user code OnCreate
			#endregion user code OnCreate			
		}
		
		/// &lt;summary&gt;
		/// Called when user is retreiving an entity from storage
		/// &lt;/summary&gt;
		protected virtual void OnMaterialize()
		{
			#region user code OnMaterialize
			#endregion user code OnMaterialize
		}
		
		public virtual System.String ModifiePar
		{
			get
			{
				System.String  value = this.m_ModifiePar;
				#region user code get public System.String ModifiePar
				#endregion user code get public System.String ModifiePar
				return value; 
			}
		}
		
		public virtual System.DateTime ModifieLe
		{
			get
			{
				System.DateTime  value = this.m_ModifieLe;
				#region user code get public System.String ModifieLe
				#endregion user code get public System.String ModifieLe
				return value; 
			}
		}
		
		public virtual System.String TableName
		{
			get
			{
				System.String  value = this.m_TableName;
				#region user code get public System.String TableName
				#endregion user code get public System.String TableName
				return value; 
			}
		}
		
		protected abstract System.String m_ModifiePar { get; }
		
		protected abstract System.String m_TableName { get; }
		
		protected abstract System.DateTime m_ModifieLe { get; }
		
		</xsl:otherwise></xsl:choose>		
		
		<xsl:apply-templates select="*[*[not(@inherited='true')]]" mode="protected"/>

		#region user code class
		#endregion user code class
	}
}
</xsl:template>

<xsl:template match="*[typing:interface]">---- File: merge <xsl:value-of select="translate(env:NamespaceName(typing:interface/@type),'.','\')"/>\<xsl:value-of select="env:TypeName(typing:interface/@type)"/>.cs
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;

#region user code using
#endregion user code using

namespace <xsl:value-of select="env:NamespaceName(typing:interface/@type)"/>
{
	<xsl:variable name="log" select="env:Log(concat('Processing type ', env:TypeName(typing:entity/@type)),'0')" xmlns:env="urn:xmd-environment"/>
	<xsl:variable name="progress" select="env:UpdateProgress()" xmlns:env="urn:xmd-environment"/>
	#region user code namespace
	#endregion user code namespace
	

	<xsl:call-template name="summary"/>
	public interface <xsl:value-of select="env:TypeName(typing:interface/@type)"/>
	#region user code implements
	#endregion user code implements
	{
	<xsl:apply-templates select="*[*[not(@inherited='true')]]" mode="interface"/>
	
		#region user code interface
		#endregion user code interface
	}
}
</xsl:template>

<xsl:template match="*[typing:property]" mode="public"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:property/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<xsl:if test='typing:property/@length >= 0'>
		public const int <xsl:value-of select="$public-name"/>Length = <xsl:value-of select="typing:property/@length"/>;
		</xsl:if>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/>
		public virtual <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
		{
			get
			{
				<xsl:value-of select="$type"/> value = this.<xsl:value-of select="$protected-name"/>;
				#region user code get public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				#endregion user code get public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				return value; 
			}
			set
			{ 
				#region user code set public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				#endregion user code set public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>				
				this.<xsl:value-of select="$protected-name"/> = value;
				On<xsl:value-of select="$public-name"/>Changed();
			}
		}
		
		public event EventHandler <xsl:value-of select="$public-name"/>Changed;
		
		protected virtual void On<xsl:value-of select="$public-name"/>Changed()
		{				
			if(<xsl:value-of select="$public-name"/>Changed != null)
				<xsl:value-of select="$public-name"/>Changed(this, System.EventArgs.Empty);			
					
			#region user code On<xsl:value-of select="$public-name"/>Changed
			#endregion user code On<xsl:value-of select="$public-name"/>Changed				
		}
</xsl:template>

<xsl:template match="*[typing:property]" mode="interface"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:property/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/><xsl:text>		
		</xsl:text><xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/> 
		{ 
			get; 
			set; 
		}
		
</xsl:template>

<xsl:template name="defaultValues">
	<xsl:for-each select="*[typing:property and not(typing:property/@inherited='true')]">
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
      <xsl:value-of select="$public-name"/> = <xsl:apply-templates select="typing:property/@type"/>;		
	</xsl:for-each>
</xsl:template>

<xsl:template match="*[typing:reference[@multiplicity = '1']]" mode="public"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/>
		public virtual <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
		{
			get
			{
				<xsl:value-of select="$type"/> value = this.<xsl:value-of select="$protected-name"/>;
				#region user code get public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				#endregion user code get public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				return value; 
			}
			set
			{ 
				#region user code set public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				#endregion user code set public <xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/>
				this.<xsl:value-of select="$protected-name"/> = value; 
				On<xsl:value-of select="$public-name"/>Changed();
			}
		}
		
		public event EventHandler <xsl:value-of select="$public-name"/>Changed;
		
		protected virtual void On<xsl:value-of select="$public-name"/>Changed()
		{			
			if(<xsl:value-of select="$public-name"/>Changed != null)
				<xsl:value-of select="$public-name"/>Changed(this, System.EventArgs.Empty);
				
			#region user code On<xsl:value-of select="$public-name"/>Changed
			#endregion user code On<xsl:value-of select="$public-name"/>Changed
		}
</xsl:template>

<xsl:template match="*[typing:reference[@multiplicity = '1']]" mode="interface"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/><xsl:text>		
		</xsl:text><xsl:value-of select="$type"/> <xsl:value-of select="$public-name"/> 
		{ 
			get; 
			set; 
		}
</xsl:template>

 <xsl:template match="*[typing:reference[@multiplicity = '*']]" mode="public"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/>
		public virtual IList&lt;<xsl:value-of select="$type"/>&gt; <xsl:value-of select="$public-name"/>
		{
			get { return this.<xsl:value-of select="$protected-name"/>; }
		}
</xsl:template>

 <xsl:template match="*[typing:reference[@multiplicity = '*']]" mode="interface"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/></xsl:variable>
		<xsl:variable name="public-name"><xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="$public-name"/></xsl:variable>
		<xsl:call-template name="summary"/><xsl:text>		
		</xsl:text>IList&lt;<xsl:value-of select="$type"/>&gt; <xsl:value-of select="$public-name"/>
		{
			get;
		}
		
</xsl:template>

<xsl:template match="*[typing:property]" mode="protected"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:property/@type), ' ')"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		protected abstract <xsl:value-of select="$type"/> <xsl:value-of select="$protected-name"/> { get; set; }
</xsl:template>

<xsl:template match="*[typing:reference[@multiplicity = '1']]" mode="protected"><xsl:variable name="type"><xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/></xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		protected abstract <xsl:value-of select="$type"/> <xsl:value-of select="$protected-name"/> { get; set; }
</xsl:template>

<xsl:template match="*[typing:reference[@multiplicity = '*']]" mode="protected">
	<xsl:variable name="type">
		<xsl:value-of select="concat(env:FullTypeName(typing:reference/@type), ' ')"/>
	</xsl:variable>
		<!--<xsl:variable name="protected-name"><xsl:value-of select="env:ProtectedName(local-name(.))"/></xsl:variable>-->
		<xsl:variable name="protected-name">m_<xsl:value-of select="env:PublicName(local-name(.))"/></xsl:variable>
		protected abstract IList&lt;<xsl:value-of select="$type"/>&gt; <xsl:value-of select="$protected-name"/> { get; }
</xsl:template>

<xsl:template name="summary">
<!--<xsl:if test="text()"><xsl:text disable-output-escaping="yes"><![CDATA[
	/// <summary>]]></xsl:text>
	/// <xsl:value-of select="text()" disable-output-escaping="yes"/><xsl:text disable-output-escaping="yes"><![CDATA[
	/// </summary>]]></xsl:text></xsl:if>-->
</xsl:template>

</xsl:stylesheet>